//
//  GuidePageViewController.m
//  项目A --半糖
//
//  Created by romana on 16/6/3.
//  Copyright © 2016年 romana. All rights reserved.
//

#import "GuidePageViewController.h"
#import "MyTabBarController.h"

#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height

@interface GuidePageViewController ()<UIScrollViewDelegate>


@property(nonatomic,strong)UIPageControl *myPage;
@property(nonatomic,strong)UIScrollView *scrollView;

@end

@implementation GuidePageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    
    self.scrollView.backgroundColor = [UIColor yellowColor];
    self.scrollView.contentSize = CGSizeMake(WIDTH * 4, 0);
    
    [self.view addSubview:self.scrollView];
    
    self.scrollView.pagingEnabled = YES;
    self.scrollView.showsHorizontalScrollIndicator = NO;
    self.scrollView.bounces = NO;
    self.scrollView.delegate = self;
    
    
    for (int i = 0; i < 3; i++) {
        UIScrollView *smallScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(i * WIDTH, 0, WIDTH, HEIGHT)];
        smallScroll.backgroundColor = [UIColor redColor];
        smallScroll.delegate = self;
        //        smallScroll.minimumZoomScale = 0.5;
        //        smallScroll.maximumZoomScale = 2.0;
        [self.scrollView addSubview:smallScroll];
        
        UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
        imageV.image = [UIImage imageNamed:[NSString stringWithFormat:@"picture%d.jpg",i]];
        [smallScroll addSubview:imageV];
        
    }
    
    self.myPage = [[UIPageControl alloc] initWithFrame:CGRectMake(WIDTH / 2 - 75, HEIGHT - 100, 150, 50)];
    self.myPage.backgroundColor = [UIColor blackColor];
    [self.view addSubview:self.myPage];
    
    self.myPage.numberOfPages = 3;
    self.myPage.alpha = 0.7;
    self.myPage.layer.masksToBounds = YES;
    self.myPage.layer.cornerRadius = 10;
    [self.myPage addTarget:self action:@selector(pageAction:) forControlEvents:UIControlEventValueChanged];
    
    
    UIButton *intoButton = [UIButton buttonWithType:UIButtonTypeCustom];
    intoButton.frame = CGRectMake(WIDTH - 100, 10, 80, 50);
    intoButton.backgroundColor = [UIColor colorWithRed:139 / 255.0 green:101 / 255.0 blue:8 / 255.0 alpha:0.8];
   
    intoButton.layer.masksToBounds = YES;
    intoButton.layer.cornerRadius = 10;
    [intoButton setTitle:@"开始体验" forState:UIControlStateNormal];
    [self.view addSubview:intoButton];
    [intoButton addTarget:self action:@selector(intoButton) forControlEvents:UIControlEventTouchUpInside];
    
    // Do any additional setup after loading the view, typically from a nib.
}
-(void)pageAction:(UIPageControl *)page{
    //  UIScrollView *scroll = [self.view viewWithTag:100001];
    [self.scrollView setContentOffset:CGPointMake(WIDTH * page.currentPage, 0) animated:YES];
    
    
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    
    
    self.myPage.currentPage = ((scrollView.contentOffset.x)) / WIDTH;
    
    
    
}



-(void)intoButton{
    
    
    MyTabBarController *myTabBar = [[MyTabBarController alloc]init];
    
    [self presentViewController:myTabBar animated:YES completion:^{
        
        
    }];
    
    [[NSUserDefaults standardUserDefaults]setObject:@"1" forKey:@"firstLaunch"];
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
